package com.fy.service.imbusiness.controller;

import com.fy.service.service.SkImUserFriendsService;
import com.fy.service.service.SkImUserLabelService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.fy.framework.common.model.R;
import com.fy.framework.component.config.LocaleMessage;
import com.fy.common.entity.SkImUserLabel;
import com.fy.common.util.TokenUtil;
import com.fy.common.dto.UserLabelSetDto;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户标签
 * 
 * @author zhshuo
 * @date 2021/12/01 10:43
 **/
@Slf4j
@RestController
@AllArgsConstructor
@Api(tags = "用户标签")
@RequestMapping("/user/label")
public class SkImUserLabelController {

    LocaleMessage localeMessage;

    SkImUserLabelService userLabelService;

    SkImUserFriendsService userFriendsService;

    @PostMapping
    @ApiOperation("标签添加")
    public R<?> post(@RequestBody SkImUserLabel imUserLabel) {
        boolean res = userLabelService.insert(imUserLabel.setSkImUserId(TokenUtil.getUserId()));
        return res ? R.success(localeMessage.getMessage("im.common.success"))
            : R.failedAlter(localeMessage.getMessage("im.common.failedful"));
    }

    /**
     * 指定用户标签列表
     * 
     * @return {@link R}
     */
    @PostMapping("/simpleList")
    @ApiOperation("指定用户标签列表")
    public R<Object> simpleList() {
        return R.success(userLabelService.selectList(
            new EntityWrapper<SkImUserLabel>().eq("sk_im_user_id", TokenUtil.getUserId()).orderBy("created_time",
                Boolean.FALSE)));
    }

    /**
     * 标签列表 包括标签对应人数以及标签中对应的用户名
     * 
     * @return {@link R}
     */
    @PostMapping("/list")
    @ApiOperation("指定用户标签列表包含人数以及用户")
    public R<Object> list() {
        userLabelService.list(TokenUtil.getUserId());
        return null;
    }

    /**
     * 设置用户标签
     * 
     * @param userLabelSetDto
     *            参数
     * @return {@link R}
     */
    @PostMapping("/set")
    @ApiOperation("设置用户标签")
    public R<Object> set(@RequestBody UserLabelSetDto userLabelSetDto) {
        Integer res = userFriendsService.userLabelSet(userLabelSetDto.setSkImUserId(TokenUtil.getUserId()));
        return res != null && res > 0 ? R.success(localeMessage.getMessage("im.common.successful"))
            : R.failedAlter(localeMessage.getMessage("im.common.failedful"));
    }

}
